﻿using GameEngine.Clients.Silverlight;
using GameEngine.Clients.Silverlight.View.Components;
using GameEngine.Model.Data;
using MySettlers.View.Components;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using MySettlers.View;
using System.Windows;

namespace MySettlers.Commands
{
    public class Page_Game_NewThing_In_Command : SimpleCommand
    {
        override public void Execute(INotification notification)
        {
            NewThingUC view = new NewThingUC();
            NewThingMediator med = new NewThingMediator(view, MyFacade.PAGE_GAME_NEWTHING_OUT_COMMAND);
            Facade.RegisterMediator(med);
        }
    }

    public class Page_Game_NewThing_Out_Command : SimpleCommand
    {
        override public void Execute(INotification notification)
        {
            NewThingMediator med = Facade.RetrieveMediator(NewThingMediator.MYNAME) as NewThingMediator;
            switch (notification.Body as string)
            {
                case NewThingUC.OKBUTTON:
                    if (med.ViewComponent.SelectedThingTypeId.HasValue)
                    {
                        var selectedThingType = new ThingTypeVOId(med.ViewComponent.SelectedThingTypeId.Value);
                        //item.Position = MySmurfsFacade.Instance.MyWorld.Map.CameraPosition;
                        IThingVO<int> thing = MyModel.Instance.CreateThingVO(
                                 new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()),
                                 selectedThingType);
                        SilverlightViewFacade.Helper.AddThingToWorld(
                           thing,
                           MyFacade.Instance.currentWorldId
                        );

                        SilverlightApplicationFacadeHelper.ControlThingPosition(thing.Id);
                        med.ViewComponent.DialogResult = true;
                    }
                    else
                    {
                        MessageBox.Show("Select one item");
                    }
                    break;
                case NewThingUC.CANCELBUTTON:

                    med.ViewComponent.DialogResult = false;
                    break;
            }
            Facade.RemoveMediator(NewThingMediator.MYNAME);          
        }
    }
}
